package com.project.springboot.json;

import java.io.Serializable;

public class ResultMsg<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private String code;

    private String msg;

    private T result;

    public ResultMsg() {

    }

    public ResultMsg(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResultMsg(String code, String msg, T result) {
        this.code = code;
        this.msg = msg;
        this.result = result;
    }

    public static ResultMsg<Void> error() {
        return new ResultMsg<>(RespCode.ERROR.getValue(), RespCode.ERROR.getLabel());
    }

    public static ResultMsg<Void> error(String msg) {
        return new ResultMsg<>(RespCode.ERROR.getValue(), msg);
    }

    public static ResultMsg<Void> error(String code, String msg) {
        return new ResultMsg<>(code, msg);
    }

    public static ResultMsg<Void> error(RespCode respCode) {
        return error(respCode.getValue(), respCode.getLabel());
    }

    public static ResultMsg<Void> success() {
        return new ResultMsg<>(RespCode.SUCCESS.getValue(), RespCode.SUCCESS.getLabel());
    }

    public static ResultMsg<Void> success(String msg) {
        return new ResultMsg<>(RespCode.SUCCESS.getValue(), msg);
    }

    public static <T> ResultMsg<T> success(String msg, T result) {
        return new ResultMsg<>(RespCode.SUCCESS.getValue(), msg, result);
    }

    public static <T> ResultMsg<T> ok(T result) {
        return new ResultMsg<>(RespCode.SUCCESS.getValue(), RespCode.SUCCESS.getLabel(), result);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public enum RespCode {
        SUCCESS("A00000","成功"),//success
        Q00301("Q00301","参数错误"),//API error
        Q00304("Q00304","合作方不存在"),//API error
        Q00306("Q00306","服务不可用"),//API error
        Q00307("Q00307","签名错误"),//error request
        Q00308("Q00308","请求超时"),//forbidden
        ERROR("Q00332","系统错误"),
        Q00334("Q00334","请求未找到"),
        Q00336("Q00336","无操作权限"),
        Q00339("Q00339","用户未登录"),
        Q00340("Q00340","登录账号或密码错误"),
        Q00399("Q00399","未知错误"),
        Q00401("Q00401","患者信息查询失败"),
        Q00407("Q00407","处方上传失败"),
        Q00408("Q00408","处方上传失败，处方已存在"),
        Q00409("Q00409","处方不存在"),
        Q00410("Q00410","处方号已存在"),
        Q00411("Q00411","药品信息未匹配"),
        Q00412("Q00412","药品库存不足"),
        Q00413("Q00413","查询医生信息失败"),
        Q00414("Q00414","医生信息未审核"),
        Q00416("Q00416","系统自动审方不通过"),
        Q00417("Q00417","处方已被人工审核过"),
        Q00420("Q00420","药品信息缺失"),
        Q00501("Q00501","订单不存在"),
        Q00502("Q00502","订单已存在"),
        Q00509("Q00509","订单创建失败"),
        Q00510("Q00510","物流在线下单失败"),
        Q00601("Q00601","患者配送地址查询失败"),
        Q00602("Q00602","患者信息不存在")
        ;

        private String value;
        private String label;

        RespCode(String value, String label) {
            this.value = value;
            this.label = label;
        }

        public String getLabel() {
            return label;
        }

        public void setLabel(String label) {
            this.label = label;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

    }
}
